<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增店铺轮播')" />
    <th:block th:include="include :: bootstrap-fileinput-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-shopCarouse-add">
            <div class="form-group">
                <label class="col-sm-3 control-label">上传图片：</label>
                <div class="col-sm-8">
                    <div class="file-loading">
                        <input id="imgFile" name="imgFile" class="file" type="file"  data-theme="fas" accept=".jpg,.img,.png">
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">状态：</label>
                <div class="col-sm-8">
                    <label class="toggle-switch switch-solid">
                        <input type="checkbox" id="status" checked>
                        <span></span>
                    </label>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: bootstrap-fileinput-js" />
    <script type="text/javascript">
        var prefix = ctx + "shopCarouse/shopCarouse"

        $("#form-shopCarouse-add").validate({
            focusCleanup: true
        });
        $("#imgFile").fileinput({
            uploadAsync:false,//默认异步上传
            showUpload:false,//是否显示上传按钮
        })
        function submitHandler() {
            if ($.validate.form()) {
                if ($('#imgFile')[0].files[0] == null) {
                    $.modal.alertWarning("请先选择文件路径");
                    return false;
                }
                var formData = new FormData($("#form-shopCarouse-add")[0]);
                var status = $("input[id='status']").is(':checked') == true ? 0 : 1;
                formData.append('status',status);
                formData.append('imgFile', $('#imgFile')[0].files[0]);
                var loading;
                $.ajax({
                    url: prefix + "/add",
                    type: 'post',
                    cache: false,
                    data: formData,
                    processData: false,
                    contentType: false,
                    dataType: "json",
                    beforeSend:function(){
                        loading = layer.load(1, {
                            shade: [0.5,'#000'] //0.1透明度的背景
                        })

                    },
                    success: function(result) {
                        layer.close(loading);
                        $.operate.successCallback(result);
                    }
                });

            }
        }
    </script>
</body>
</html>